﻿@model  Model.PageRole
@{
    ViewBag.Title = "模型列表";
    Layout = "~/Views/Shared/_Main.cshtml";
}
@section Head{
    <style>
        .modelType
        {
            height: 470px;
            padding-left: 5px;
            padding-right: 5px;
        }
        select
        {
            width: 90px;
        }
        .ov
        {
            overflow-y: scroll;
        }
    </style>
    <script type="text/javascript">
        var clickAll = true;
        var UrlArray = $.getUrlArray();
        var pageRole = '@Model.role';
        var retArr = new Array();
        var ExpIDs = new Array();
        var selectCount = 1;
        var opts = {
            rows: 10,
            height: 450,
            url: "/ModelConfig/GetList",
            para: { TypeID: "2", dbName: encodeURI(UrlArray["dbName"]) },
            idField: "GUID",
            checkbox: true,
            columns: [
                    { field: 'TableName', title: '模型名称', width: 30, sortable: true },
                    { field: 'TableDescription', title: '模型描述', width: 40, sortable: true },
                    { field: 'TableType', title: '模型状态', width: 10, align: 'center' },
                    { field: 'IsRecord', title: '版本记录', width: 10, align: 'center' },
                    { field: 'CreateTime', title: '创建时间', width: 10, align: 'center', sortable: true }
                    ],
            OnChickRow: function (value, rowData, rowIndex) {
                return clickRow(value, rowData, rowIndex, true);
            }
        };
        function clickRow(value, rowData, rowIndex, load) {
            var s = true;
            if (s && UrlArray["reference"] == "1" && ExpIDs.length > 0) {
                alert("模型只可选择1个，请检查选择项。");
                s = false;
                return false;
            }
            if (s) {
                $("#sel_content").append("<span class='s1 s1" + value + "'><a title='" + rowData.TableDescription + "'>" + rowData.DefaultView + "</a><span class='s2 s2" + value + "''>&nbsp;X&nbsp;</span></span>");

                $(".s2" + value).bind("click", function () {
                    $(".s1" + value).remove();
                    $(".s2" + value).remove();
                    for (var j = 0; j < retArr.length; j++) {
                        if (retArr[j].GUID == value) {
                            retArr.removeAt(j);
                        }
                    }
                    ExpIDs.removeValue(value);
                    opts.para["ExpIDs"] = ExpIDs.join(",");
                    initTable("DataGrid2", opts);
                });
                retArr.push(rowData);
                ExpIDs.push(value);
                if (load) {
                    opts.para["ExpIDs"] = ExpIDs.join(",");
                    initTable("DataGrid2", opts);
                }
            }
            return true;
        }
        $(function () {
            if (UrlArray["TypeID"]) {//指定分类下的模型列表，可管理
                $("#selected").hide();
                $("#back").show();
                $("#div_main").removeClass("ov");
                $("#type_Name").html(UrlArray["TypeName"] + "-");
                opts.checkbox = false;
                opts.para["TypeID"] = UrlArray["TypeID"];
                opts.columns[0]["field"] = "TableName";
                opts.columns[1]["width"] = 28;
                opts.columns[5] = { field: 'GUID', title: '操作', width: 12, align: 'center', formatter: function (value, rowData, rowIndex) {
                    var a = "<select onchange=\"DoAction(this.options.selectedIndex,'" + value + "')\"><option value=''>-请选择-</option>";
                    if (pageRole == '2')
                        return a + "<option>修改</option><option>删除</option><option>复制模型</option><option>发送到实例</option><option>查看渐变维度</option><option>跟踪</option><option>查看模型数据</option><option>查看数据质量数据</option></select>";
                    else
                        return a + "<option>查看渐变维度</option><option>跟踪</option><option>查看模型数据</option><option>查看数据质量数据</option></select>";
                }
                };
            }
            if (UrlArray["type"]) {//所有模型分类列表
                opts.checkbox = true;
                opts.para["TypeID"] = UrlArray["type"];
                opts.columns.removeAt(2);
                opts.columns[1]["width"] = 50;
            }
            if (UrlArray["step"]) {
                opts.para["step"] = UrlArray["step"];
                opts.columns[2]["field"] = "vwName";
                opts.columns[2]["title"] = "源系统视图名";
                opts.columns[2]["align"] = "left";
                opts.columns[2]["width"] = 25;
                opts.columns[1]["width"] = 25;
            }
            if (UrlArray["tarSysID"]) {
                opts.para["tarSysID"] = UrlArray["tarSysID"];
            }
            InitList();
        });
        function ModelTableInfo(v, t) {
            showModalMany('Info', '/ODSConfig/TableInfo?modelID=' + v + '&dbName=' + encodeURI(UrlArray["dbName"]) + '&tbName=' + t, '900', '480');
            InitList();
        }
        function DoAction(i, v, t) {
            if (pageRole == '1') {
                i = i + 4;
            }
            switch (i) {
                case 1:
                    addData(v, t);
                    break;
                case 2:
                    DelData(v, t);
                    break;
                case 3:
                    window.location = "/ModelConfig/CopyModel?modelID=" + v + "&dbName=" + encodeURI(UrlArray["dbName"]);
                    break;
                case 4:
                    window.location = "/ModelConfig/SendModel?modelID=" + v + "&dbName=" + encodeURI(UrlArray["dbName"]);
                    break;
                case 5:
                    window.location = "/ModelConfig/ConfigRecordList?modelID=" + v + "&dbName=" + encodeURI(UrlArray["dbName"]);
                    break;
                case 6:
                    GetPath(v, 'model', 0);
                    InitList();
                    break;
                case 7:
                    showModalMany('Info', '/ModelConfig/GetModelData?modelID=' + v + '&dbName=' + encodeURI(UrlArray["dbName"]), '900', '480');
                    InitList();
                    break;
                case 8:
                    showModalMany('Info', '/DQConfig/Index?modelID=' + v + '&viewDQ=1&dbName=' + encodeURI(UrlArray["dbName"]), '800', '400');
                    InitList();
                    break;
            }
        }
        function addData(id, t) {
            window.location = "/ModelConfig/End?modelID=" + id + "&dbName=" + encodeURI(UrlArray["dbName"]);
        }
        function DelData(v, t) {
            if (confirm("确定要删除吗？")) {
                $.post("/ModelConfig/Delete", { id: v, Type: 2, dbName: encodeURI(UrlArray["dbName"]) }, function (result) {
                    if (result == "1") {
                        alert("操作成功。");
                        InitList();
                    }
                    else if (result == "2")
                        alert("删除失败！模型分类下包含模型，请先删除模型分类下的模型。");
                    else
                        $("#msg").html(result);
                });
            } else
                InitList();
        }
        function InitList() {
            selectCount = UrlArray["selectCount"];
            if (typeof (selectCount) == "undefined" || selectCount == null)
                selectCount = 1;
            opts.para["tableName"] = $("#txt_TableName").val();
            opts.para["getSysName"] = UrlArray["getSysName"];
            $("#DataGrid2").dg(opts);
        }
        function btnSearch() {
            thisPageNum = 1;
            InitList();
        }
        function back() {
            window.location = "/ModelConfig/index?dbName=" + encodeURI(UrlArray["dbName"]);
        }
        function ViewList(id) {
        }
        function flexiSelect() {
            if (retArr.length < 1) {
                alert('请选择一条数据!');
                return false;
            }
            returnParent(retArr);
            return false;
        }
    </script>
}
<div id="div_main" class="modelType ov">
    <table class="listTitle">
        <tr>
            <td width="15">
                <img src="/images/search.png" />
            </td>
            <td width="300">
                模型配置搜索
            </td>
            <td align="right">
                <input type="button" id="back" value="返回" class="button" style="display: none;" onclick="back()" />
            </td>
        </tr>
    </table>
    <table class="searchArea" width="100%">
        <tr>
            <td>
                模型名称：
                <input type="text" id="txt_TableName" style="width: 300px;" />
                <input type="button" value="搜索" class="button" onclick="btnSearch()" />
            </td>
        </tr>
    </table>
    <table id="selected" style="width: 100%;">
        <tr>
            <td width="50">
                已选择：
            </td>
            <td>
                <div id="sel_content">
                </div>
            </td>
            <td width="50">
                <input type="button" value=" 确定 " class="button" onclick="flexiSelect()" />
            </td>
        </tr>
    </table>
    <table class="listTitle">
        <tr>
            <td width="15">
                <img src="/images/filesave.png" />
            </td>
            <td width="300">
                <span id="type_Name"></span>模型配置列表
            </td>
            <td align="right">
            </td>
        </tr>
    </table>
    <table id="DataGrid2" class="pagTable" cellpadding="0" cellspacing="0">
    </table>
    <div>
        <div id="Pagination" class="pagination">
        </div>
        <div id="loading" class="loading">
            <img src="/Images/tree_loading.gif" />
        </div>
    </div>
    <div id="msg">
    </div>
</div>
